﻿using GamFi.API.Application.Contracts.Chains.GetChains;
using GamFi.API.Application.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace GamFi.API.Application.Features.Queries.Chain.GetChains;

public class GetChainsQueryHandler(IDbContext dbContext) : IRequestHandler<GetChainsQuery, GetChainsResponse>
{
    public async Task<GetChainsResponse> Handle(GetChainsQuery request, CancellationToken cancellationToken)
    {
        var chains = await dbContext.Chains
            .Select(c => new GetChainsResponseItem
            {
                Id = c.Id,
                Name = c.Name,
                ImageId = c.ImageId
            })
            .ToListAsync(cancellationToken);

        return new GetChainsResponse { Chains = chains };
    }
}